//
//  MainTabBarController.swift
//  yueshijia
//
//  Created by 王磊 on 17/4/18.
//  Copyright © 2017年 王磊. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {

    var homeVC = HomeViewController()
    var specialVC = SpecialViewController()
    var storeVC = StoreViewController()
    var basketVC = BasketViewController()
    var meVC = MeViewController()
    var nav = NavigationViewController()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        homeVC.title = "首页"
        specialVC.title = "专题"
        storeVC.title = "店铺"
        basketVC.title = "购物篮"
        meVC.title = "我"
        addChildVC(childVC: homeVC, imageName: "YS_index_nor", selectedImageName: "YS_index_sel")
        addChildVC(childVC: specialVC, imageName: "YS_pro_nor", selectedImageName: "YS_pro_sel")
        addChildVC(childVC: storeVC, imageName: "YS_shop_nor", selectedImageName: "YS_shop_sel")
        addChildVC(childVC: basketVC, imageName: "YS_car_nor", selectedImageName: "YS_car_sel")
        addChildVC(childVC: meVC, imageName: "YS_mine_nor", selectedImageName: "YS_mine_sel")
        
        }

    func addChildVC(childVC: UIViewController,   imageName: NSString,selectedImageName: NSString) {
        childVC.tabBarItem.image = UIImage.init(named: imageName as String)
        childVC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.init(red: 230, green: 198, blue: 168, alpha: 1)], for: .normal)
        childVC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.init(red: 211, green: 192, blue: 162, alpha: 1)], for: .selected)
        //tabbar默认为蓝色 改变了点击时候的图片，还是默认蓝色的 设置它的渲染模式
        childVC.tabBarItem.selectedImage = UIImage.init(named: selectedImageName as String)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
       
        nav = NavigationViewController.init(rootViewController: childVC)
        self.addChildViewController(nav)
    }

}
